package br.com.news.business;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.business.utils.GenericBusiness;
import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IAnuncioBusiness;
import br.com.news.utils.database.beans.AnuncioBean;
import br.com.news.utils.database.exception.DataBaseServiceException;
import br.com.news.utils.database.interfaces.IAnuncioServiceDb;

@Named
public class AnuncioBusiness extends GenericBusiness implements IAnuncioBusiness{

	@Inject
	private IAnuncioServiceDb anuncioServiceDb;
	
	@Override
	public List<AnuncioBean> findAll() throws BusinessException {
		try {
			return anuncioServiceDb.findAll();
		} catch (DataBaseServiceException e) {
			throw new BusinessException(e);
		}
		
	}
	
	@Override
	public void save(AnuncioBean anuncio) throws BusinessException {
		try {
			anuncioServiceDb.insert(anuncio);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("Erro ao tentar salvar o anuncio na camada de business",e);
		}
	}
	
	@Override
	public void update(AnuncioBean anuncio) throws BusinessException {
		try {
			anuncioServiceDb.update(anuncio);
		} catch (DataBaseServiceException e) {
			throw new BusinessException("Erro ao tentar dar update o anuncio na camada de business",e);
		}
	}
	
	@Override
	public List<AnuncioBean> buscaAnunciosNaoEnviados() {
		return anuncioServiceDb.buscaAnunciosNaoEnviados();
	}

}
